package cn.tedu.boot011.controller;

import cn.tedu.boot011.entity.User;
import cn.tedu.boot011.util.DBUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@Controller
public class regController {
    @RequestMapping("/reg")
    @ResponseBody
    public String reg(User p){

        System.out.println("p = " + p);
        try(
                Connection con = DBUtil.getConnection();
        ) {
          String sql = "INSERT INTO user values(null,?,?,?)";
            PreparedStatement pres = con.prepareStatement(sql);
            pres.setString(1,p.getUsername());
            pres.setString(2, p.getPassword());
            pres.setString(3,p.getNickname());
            pres.executeUpdate();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return "注册成功";



    }
}
